import 'dart:io';

import 'package:get/get.dart';
import 'package:my_app/app/core/utils/date_util.dart';

class ImageToolController extends GetxController {
  ImageToolController();

  Rx<File?> beforeCompressFile = Rx<File?>(null); //压缩前文件

  Rx<File?> afterCompressFile = Rx<File?>(null);

  Rx<String> watermark = DateUtil.formatDate(DateTime.now()).obs;

  Rx<File?> watermarkFile = Rx<File?>(null);

  void changeBeforeCompressFile(File file) => {beforeCompressFile.value = file};

  void changeAfterCompressFile(File file) => {afterCompressFile.value = file};

  void changeWatermarkFile(File? file) => {watermarkFile.value = file};

  void changeWatermark(String value) => {watermark.value = value};

  String get beforeCompressFileSize => beforeCompressFile.value != null
      ? (beforeCompressFile.value!.lengthSync() / 1024 / 1000)
          .toStringAsFixed(2)
      : "0";

  String get afterCompressFileSize => afterCompressFile.value != null
      ? (afterCompressFile.value!.lengthSync() / 1024 / 1000).toStringAsFixed(2)
      : "0";
}
